<template>
  <div class="drag-wrap" id="wrap" @drop="drop" @dragover="allDrop">
    <div class="wrap">
      <div id="div1" class="drag-box" @drop="drop" @dragover="allDrop"></div>
      <div id="div2" class="drag-box" @drop="drop" @dragover="allDrop"></div>
      <div id="div3" class="drag-box" @drop="drop" @dragover="allDrop"></div>
    </div>
    <div class="box" id="drag1" @dragstart="drag" draggable="true"></div>
    <div class="box blue" id="drag2" @dragstart="drag" draggable="true"></div>
    <!-- <img 
    id="drag1"
    src="https://www.w3school.com.cn/i/eg_mouse.jpg" 
    alt=""
    @dragstart="drag"
    draggable="true">
    <img 
    id="drag2"
    src="https://www.w3school.com.cn/i/eg_dragdrop_w3school.gif" 
    alt=""
    @dragstart="drag"
    draggable="true"> -->
  </div>
</template>

<script>
export default {
  methods:{
    allDrop(e){
      e.preventDefault()
    },
    drag(e){
      e.dataTransfer.setData('Text', e.target.id)
    },
    drop(ev){
      ev.preventDefault();
      var data=ev.dataTransfer.getData("Text"); // 這裡是一個id zj
      ev.target.appendChild(document.getElementById(data));
      
    }
  },
  mounted(){

  }
}
</script>

<style lang="less" scoped>
.drag-wrap{
  width: 100vw;
  height: 100vh;
  background-color: #8e8e8e;
  overflow: hidden;
  text-align: center;
  .wrap{
    display: flex;
    justify-content: center;
    &:first-child{
      margin-right: 20px;
    }
  }
  .drag-box{
    width: 250px;
    height: 200px;
    border: 5px solid red;
    margin: 50px auto;
    display: grid;
    place-items: center;
    // position: absolute;
    // left: 0;
    // top: 0;
  }
  .box{
    width: 100px;
    min-height: 100px;
    background-color: chocolate;
  }
  .blue{
    min-height: 200px;
    background-color: cornflowerblue;
  }
}

</style>